TopBarView = Backbone.View.extend({
  render: function() {
    var that = this;
    return $.get('template?name=shared.top_bar').then(function(data) {
      that.template = _.template(data);
      that.$el.html(that.template());
    });
  }
});

UserProfileView = BaseView.extend({
  className: 'full_height',
  events:{
    "click .switch_language": "switchLanguage",
    "click .link_portal":"linkPortal",
  },
  initialize: function(obj) {
  },
  render: function () {
    var json = this.model.toJSON();

    //TODO, set the list of size

    this.$el.html(this.template(json));
    $('._dialog_overlay').remove();

    return this;
  },
  switchLanguage:function(event){
    var target = event.target;
    var languageSwitched = $(target).attr('name');
    $.ajax({
            method: "GET",
            url: 'switchLanguage',
            data: {locale: languageSwitched},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        }).then(function(result) {
          console.log(result);
          window.location.reload() 
        });
  },
  linkPortal:function(event){
    var target = event.target;
    var language = $(target).attr('name');
    if(language == 'zh'){
      var url = $('#zh_url').html();
    }else{
      var url = $('#en_url').html();
    }
        $.ajax({
            method: "GET",
            url: 'linkPortal',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        }).then(function(result) {
          window.location.href = url;
        });
  }
});
